package me.firstapp.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;

import me.firstapp.spi.bbs.AdvertisementService;
import me.firstapp.spi.bbs.CollectionService;
import me.firstapp.spi.bbs.EmailService;
import me.firstapp.spi.bbs.MemberService;
import me.firstapp.spi.bbs.NotificationService;
import me.firstapp.spi.bbs.ReplyService;
import me.firstapp.spi.bbs.SearchService;
import me.firstapp.spi.bbs.SectionService;
import me.firstapp.spi.bbs.TopicService;
import me.firstapp.spi.bbs.impl.AdvertisementServiceImpl;
import me.firstapp.spi.bbs.impl.CollectionServiceImpl;
import me.firstapp.spi.bbs.impl.EmailServiceImpl;
import me.firstapp.spi.bbs.impl.MemberServiceImpl;
import me.firstapp.spi.bbs.impl.NotificationServiceImpl;
import me.firstapp.spi.bbs.impl.ReplyServiceImpl;
import me.firstapp.spi.bbs.impl.SearchServiceImpl;
import me.firstapp.spi.bbs.impl.SectionServiceImpl;
import me.firstapp.spi.bbs.impl.TopicServiceImpl;
import me.firstapp.spi.shop.AddressService;
import me.firstapp.spi.shop.CategoryService;
import me.firstapp.spi.shop.OrderService;
import me.firstapp.spi.shop.PointRechargeCardService;
import me.firstapp.spi.shop.PointService;
import me.firstapp.spi.shop.ProductCommentService;
import me.firstapp.spi.shop.ProductService;
import me.firstapp.spi.shop.ProductSkuRelService;
import me.firstapp.spi.shop.ShoppingCartService;
import me.firstapp.spi.shop.SkuService;
import me.firstapp.spi.shop.impl.AddressServiceImpl;
import me.firstapp.spi.shop.impl.CategoryServiceImpl;
import me.firstapp.spi.shop.impl.OrderServiceImpl;
import me.firstapp.spi.shop.impl.PointRechargeCardServiceImpl;
import me.firstapp.spi.shop.impl.PointServiceImpl;
import me.firstapp.spi.shop.impl.ProductCommentServiceImpl;
import me.firstapp.spi.shop.impl.ProductServiceImpl;
import me.firstapp.spi.shop.impl.ProductSkuRelServiceImpl;
import me.firstapp.spi.shop.impl.ShoppingCartServiceImpl;
import me.firstapp.spi.shop.impl.SkuServiceImpl;
import me.firstapp.spi.system.ApiClientService;
import me.firstapp.spi.system.EmailConfigService;
import me.firstapp.spi.system.OperatorService;
import me.firstapp.spi.system.StatisticsService;
import me.firstapp.spi.system.impl.ApiClientServiceImpl;
import me.firstapp.spi.system.impl.EmailConfigServiceImpl;
import me.firstapp.spi.system.impl.OperatorServiceImpl;
import me.firstapp.spi.system.impl.StatisticsServiceImpl;
import me.firstapp.spi.zerone.CqsscService;
import me.firstapp.spi.zerone.impl.CqsscServiceImpl;

@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

	@Bean
	public MemberService memberService() {
		return new MemberServiceImpl();
	}

	@Bean
	public SectionService sectionService() {
		return new SectionServiceImpl();
	}

	@Bean
	public TopicService topicService() {
		return new TopicServiceImpl();
	}

	@Bean
	public ProductService productService() {
		return new ProductServiceImpl();
	}

	@Bean
	public SkuService skuService() {
		return new SkuServiceImpl();
	}

	@Bean
	public AddressService addressService() {
		return new AddressServiceImpl();
	}

	@Bean
	public NotificationService notificationService() {
		return new NotificationServiceImpl();
	}

	@Bean
	public OrderService orderService() {
		return new OrderServiceImpl();
	}

	@Bean
	public ShoppingCartService shoppingCartService() {
		return new ShoppingCartServiceImpl();
	}

	@Bean
	public PointRechargeCardService pointRechargeCardService() {
		return new PointRechargeCardServiceImpl();
	}

	@Bean
	public CollectionService collectionService() {
		return new CollectionServiceImpl();
	}

	@Bean
	public EmailService emailService() {
		return new EmailServiceImpl();
	}

	@Bean
	public ReplyService replyService() {
		return new ReplyServiceImpl();
	}

	@Bean
	public CategoryService categoryService() {
		return new CategoryServiceImpl();
	}

	@Bean
	public PointService pointService() {
		return new PointServiceImpl();
	}

	@Bean
	public ProductSkuRelService productSkuRelService() {
		return new ProductSkuRelServiceImpl();
	}

	@Bean
	public ProductCommentService productCommentService() {
		return new ProductCommentServiceImpl();
	}

	@Bean
	public AdvertisementService advertisementService() {
		return new AdvertisementServiceImpl();
	}

	@Bean
	public SearchService searchService() {
		return new SearchServiceImpl();
	}

	@Bean
	public ApiClientService apiClientService() {
		return new ApiClientServiceImpl();
	}

	@Bean
	public EmailConfigService emailConfigService() {
		return new EmailConfigServiceImpl();
	}

	@Bean
	public OperatorService operatorService() {
		return new OperatorServiceImpl();
	}

	@Bean
	public StatisticsService statisticsService() {
		return new StatisticsServiceImpl();
	}

	@Bean
	public CqsscService cqsscService() {
		return new CqsscServiceImpl();
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedCqsscService(CqsscService cqsscService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(cqsscService);
		expoter.setServiceInterface(CqsscService.class);
		return expoter;
	}
	
	@Bean
	public HttpInvokerServiceExporter httpExportedStatisticsService(StatisticsService statisticsService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(statisticsService);
		expoter.setServiceInterface(StatisticsService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedOperatorService(OperatorService operatorService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(operatorService);
		expoter.setServiceInterface(OperatorService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedEmailConfigService(EmailConfigService emailConfigService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(emailConfigService);
		expoter.setServiceInterface(EmailConfigService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedApiClientService(ApiClientService apiClientService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(apiClientService);
		expoter.setServiceInterface(ApiClientService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedSearchService(SearchService searchService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(searchService);
		expoter.setServiceInterface(SearchService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedAdvertisementService(AdvertisementService advertisementService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(advertisementService);
		expoter.setServiceInterface(AdvertisementService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedProductCommentService(ProductCommentService productCommentService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(productCommentService);
		expoter.setServiceInterface(ProductCommentService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedPointService(PointService pointService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(pointService);
		expoter.setServiceInterface(PointService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedProductSkuRelService(ProductSkuRelService productSkuRelService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(productSkuRelService);
		expoter.setServiceInterface(ProductSkuRelService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedCategoryService(CategoryService categoryService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(categoryService);
		expoter.setServiceInterface(CategoryService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedReplyService(ReplyService replyService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(replyService);
		expoter.setServiceInterface(ReplyService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedEmailService(EmailService emailService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(emailService);
		expoter.setServiceInterface(EmailService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedCollectionService(CollectionService collectionService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(collectionService);
		expoter.setServiceInterface(CollectionService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedPointRechargeCardService(
			PointRechargeCardService pointRechargeCardService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(pointRechargeCardService);
		expoter.setServiceInterface(PointRechargeCardService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedShoppingCartService(ShoppingCartService shoppingCartService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(shoppingCartService);
		expoter.setServiceInterface(ShoppingCartService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedOrderService(OrderService orderService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(orderService);
		expoter.setServiceInterface(OrderService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedNotificationService(NotificationService notificationService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(notificationService);
		expoter.setServiceInterface(NotificationService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedAddressService(AddressService addressService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(addressService);
		expoter.setServiceInterface(AddressService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedMemberService(MemberService memberService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(memberService);
		expoter.setServiceInterface(MemberService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedSectionService(SectionService sectionService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(sectionService);
		expoter.setServiceInterface(SectionService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedTopicService(TopicService topicService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(topicService);
		expoter.setServiceInterface(TopicService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedProductService(ProductService productService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(productService);
		expoter.setServiceInterface(ProductService.class);
		return expoter;
	}

	@Bean
	public HttpInvokerServiceExporter httpExportedSkuService(SkuService skuService) {
		HttpInvokerServiceExporter expoter = new HttpInvokerServiceExporter();
		expoter.setService(skuService);
		expoter.setServiceInterface(SkuService.class);
		return expoter;
	}

	@Bean
	public HandlerMapping httpInvokerMapping() {
		SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
		Properties mappings = new Properties();
		mappings.setProperty("/member.service", "httpExportedMemberService");
		mappings.setProperty("/section.service", "httpExportedSectionService");
		mappings.setProperty("/topic.service", "httpExportedTopicService");
		mappings.setProperty("/product.service", "httpExportedProductService");
		mappings.setProperty("/sku.service", "httpExportedSkuService");
		mappings.setProperty("/address.service", "httpExportedAddressService");
		mappings.setProperty("/shoppingCart.service", "httpExportedShoppingCartService");
		mappings.setProperty("/order.service", "httpExportedOrderService");
		mappings.setProperty("/notification.service", "httpExportedNotificationService");
		mappings.setProperty("/pointRechargeCard.service", "httpExportedPointRechargeCardService");
		mappings.setProperty("/collection.service", "httpExportedCollectionService");
		mappings.setProperty("/email.service", "httpExportedEmailService");
		mappings.setProperty("/reply.service", "httpExportedReplyService");
		mappings.setProperty("/category.service", "httpExportedCategoryService");
		mappings.setProperty("/point.service", "httpExportedPointService");
		mappings.setProperty("/productSkuRel.service", "httpExportedProductSkuRelService");
		mappings.setProperty("/productComment.service", "httpExportedProductCommentService");
		mappings.setProperty("/advertisement.service", "httpExportedAdvertisementService");
		mappings.setProperty("/search.service", "httpExportedSearchService");
		mappings.setProperty("/apiClient.service", "httpExportedApiClientService");
		mappings.setProperty("/emailConfig.service", "httpExportedEmailConfigService");
		mappings.setProperty("/operator.service", "httpExportedOperatorService");
		mappings.setProperty("/statistics.service", "httpExportedStatisticsService");
		mappings.setProperty("/cqssc.service", "httpExportedCqsscService");
		mapping.setMappings(mappings);
		return mapping;
	}

}
